<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>按通道新增三级分销比率</title>
		<script src="js/lib/jquery-1.11.0.js"></script>
		<link rel="stylesheet" href="css/lib/bootstrap.min.css"/>
		<link rel="stylesheet" href="css/lib/loading.css" />
		<script src="js/lib/bootstrap.min.js"></script>
		<script src="js/lib/loading.js"></script>
		<script src="js/lib/angular.min.js"></script>
		<script src="js/base.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style>
		body{
			font-size:12px;
		}		
		table,
		/* th,
			td {
				border: 1px solid grey;
				border-collapse: collapse;
				padding: 5px;
				vertical-align: middle !important;
			}	 */	
		/* table td:nth-child(odd) {
			background-color: #f1f1f1;
			
		} */
		table td:nth-child(even) {
			
		}
		table tr:nth-child(even) {
			background-color:#ffffff;
		}
	</style>
	<body ng-app="myApp" ng-controller="customersCtrl">		
		<div class="">
		<!--加载动画-->
		<div class="wrapper">
            <div id="loader-wrapper">
                <div id="loader"></div>
            </div>
        </div>
			<div style="padding:15px 5px 0px 5px;border:3px solid #ccc;margin-bottom:15px">
			<table class="table table-hover">				
				<tbody>
					<tr>
						<th colspan="12" style="font-size:15px;font-weight:600;color:#666">修改产品名称及金额：</th>
					</tr>
					<tr>
						<td style="font-size:16px;font-weight:600;color:#666">产品名称:</td>
						<td colspan="12">
						<input id="msg1" ng-model="msg1" type="text" class="form-control" style="width:280px;;display:inline-block;" placeholder="请输入产品名称"/><span style="color:red">（*可修改）</span>
						</td>											
					</tr>
					<tr>
						<td style="font-size:15px;font-weight:600;color:#666">产品级别:</td>
						<td colspan="12">
						<input id="msg2" ng-model="msg2" type="text" class="form-control" style="width:280px;" readonly="readonly" />
						</td>											
					</tr>
					<tr>
						<td style="font-size:15px;font-weight:600;color:#666">升级需推人数:</td>
						<td colspan="12">
						<input id="msg3" ng-model="msg3" type="text" class="form-control" style="width:280px;;display:inline-block;" placeholder="请输入产品金额"/><span style="color:red">（*可修改）</span>
						</td>											
					</tr>
					<tr>
						<td style="font-size:15px;font-weight:600;color:#666">产品ID:</td>
						<td colspan="12">
						<input id="msg0" ng-model="msg0" type="text" class="form-control" style="width:280px;" readonly="readonly" />
						</td>											
					</tr>
					<tr>
						<td style="font-size:15px;font-weight:600;color:#666">展示方式:</td>
						<td colspan="12">
						<!-- <input id="msg-1" type="text" class="form-control" style="width:280px;" readonly="readonly" /> -->
						<select id="msg" name="" id="" class="form-control" style="width:280px;" readonly="readonly">
							<option value="0">【线上购买】显示价格</option>
							<option value="1">【联系客服】显示价格</option>
							<option value="2">【线上购买】隐藏价格</option>
							<option value="3">【联系客服】隐藏价格</option>
							<option value="4">【隐藏产品】</option>
						</select>
						</td>											
					</tr>
					<tr>
						<td style="font-size:15px;font-weight:600;color:#666">升级描述:</td>
						<td colspan="12">
							<!-- <input id="upgrade_state" v-model="upgrade_state" placeholder="请输入升级描述信息" class="form-control" type="text" style="width:280px;"/> -->
							<textarea id="upgrade_state" v-model="upgrade_state" name="" cols="60" rows="6" placeholder="请输入升级描述信息"></textarea>		
						</td>	
					</tr>
					<tr>
						<td style="font-size:15px;font-weight:600;color:#666">收益描述:</td>
						<td colspan="12">
							<!-- <input id="earnings_state" v-model="earnings_state" placeholder="请输入收益描述信息" class="form-control" type="text" style="width:280px;"/> -->
							<textarea id="earnings_state" v-model="earnings_state" name="" cols="60" rows="6" placeholder="请输入收益描述信息"></textarea>		
						</td>	
					</tr>
					<tr>
						<td colspan="12">
							<input id="btn" type="btn" value="信息变更" class="btn btn-danger" style="display:block;margin:0 300px;"/>
						</td>
					</tr>
				</tbody>
			</table>					
			</div>
			<div style="padding:15px 5px 0px 5px;border:3px solid #ccc;margin-bottom:15px">
				<table class="table table-hover"  style="width:50%;float:left;">
					<tr>
						<th style="font-size:20px;" colspan="10">设置此代理刷卡费率</th>
					</tr>
					<tr style="font-size:15px">
						<!-- <td style="width:55px;" class="text-center">序号</td> -->
						<!-- <td class="text-center">通道编号</td> -->
						<td class="text-center">通道名称</td>
						<td class="text-center">T0+T1</td>
						<td class="text-center">单笔手续费</td>
						<td class="text-center">加急费(额外费用)</td>
						<!-- <td class="text-center">当天最大金额</td> -->
						<td class="text-center">刷卡费率</td>
						<td class="text-center">费率变更</td>
						<!-- <td class="text-center">结束时间</td> -->
					</tr>
					<tr ng-repeat="item in items2" ng-show="item.status==1">
						<!-- <td class="text-center">{{$index+1}}</td> -->
						<!-- <td class="text-center">{{item.id}}</td> -->
						<td class="text-center"><img style="width:25px;height:25px;margin:0 20px 0 30px;" src="{{item.log}}" alt="log">{{item.name}}</td>
						<td class="text-center">{{item.channelParams}}</td>
						<td class="text-center">￥{{item.withdrawFee}}</td>
						<td class="text-center">￥{{item.extraFee}}</td>
						<!-- <td class="text-center">￥{{item.everyDayMaxLimit}}</td> -->
						<td  class="text-center" contenteditable="true">
							<input ng-keyup="fd(item)" type="text" ng-model="item.rate" style="width:50px;margin:0 auto;">
						</td>
						<td class="text-center"><button ng-click="add(item)">修改</button></td>
						<!-- <td class="text-center">{{item.createTime}}</td> -->
					</tr>
					<tr>
						<td colspan="10" id="show02" class="text-center" style="display:none;">
						</td>
					</tr>
				</table>
				<table class="table table-hover"  style="width:50%;float:right;">
					<tr>
						<th style="font-size:20px;" colspan="10">设置此代理还款费率</th>
					</tr>
					<tr style="font-size:15px">
						<!-- <td style="width:55px;" class="text-center">序号</td> -->
						<!-- <td class="text-center">通道编号</td> -->
						<td class="text-center">通道名称</td>
						<td class="text-center">T0+T1</td>
						<td class="text-center">单笔手续费</td>
						<td class="text-center">加急费(额外费用)</td>
						<!-- <td class="text-center">当天最大金额</td> -->
						<td class="text-center">刷卡费率</td>
						<td class="text-center">费率变更</td>
						<!-- <td class="text-center">结束时间</td> -->
					</tr>
					<tr ng-repeat="item in items2" ng-show="item.name == '信用卡消费' || item.name == '信用卡还款'">
						<!-- <td class="text-center">{{$index+1}}</td> -->
						<!-- <td class="text-center">{{item.id}}</td> -->
						<td class="text-center"><img style="width:25px;height:25px;margin:0 20px 0 30px;" src="{{item.log}}" alt="log">{{item.name}}</td>
						<td class="text-center">{{item.channelParams}}</td>
						<td class="text-center">￥{{item.withdrawFee}}</td>
						<td class="text-center">￥{{item.extraFee}}</td>
						<!-- <td class="text-center">￥{{item.everyDayMaxLimit}}</td> -->
						<td  class="text-center" contenteditable="true">
							<input ng-keyup="fd(item)" type="text" ng-model="item.rate" style="width:50px;margin:0 auto;">
						</td>
						<td class="text-center"><button ng-click="add(item)">修改</button></td>
						<!-- <td class="text-center">{{item.createTime}}</td> -->
					</tr>
					<tr>
						<td colspan="10" id="show02" class="text-center" style="display:none;">
						</td>
					</tr>
				</table>
			</div>
			</div>
		</div>
	</body>
	<script>
	$(function(){
		var bank = sessionStorage.getItem(key=15);/*获取到产品id*/
		var grade = sessionStorage.getItem(key=16);
		var name = sessionStorage.getItem(key=17);
		var money = sessionStorage.getItem(key=18);
		var upgrade_state = sessionStorage.getItem(key=190);
		var earnings_state = sessionStorage.getItem(key=200);
		$('#msg0').val(bank);
		$('#msg1').val(name);
		$('#msg2').val(grade);
		$('#upgrade_state').val(upgrade_state);
		$('#earnings_state').val(earnings_state);
		/*if(grade == 1){
			$('#ms2').val("分销商")
		}
		if(grade == 2){
			$('#ms2').val("代理商")
		}
		if(grade == 3){
			$('#ms2').val("服务商")
		}*/
		$('#msg3').val(money);
		$('#msg1').change(function(){
			var m1 = $('#msg0').val();
			var m2 = $('#msg1').val();
			console.log(m1)
			console.log(m2)
			$.ajax({
				type:"POST",/*查询通道费率*/
					url:window.baseUrl+"user/thirdlevel/channel/rate",
					async:true,
					dataType:"json",
					data:{
						thirdLevelId:m1,
						channelId:m2
					},
					success:function(data){
						console.log(data)
						/*console.log(data.result.rate)*/
						if(data.result == null){
							alert('此通道还没有设置费率！')
							$('#msg2').val(0.00)
						}else{
							$('#msg2').val(data.result.rate)
						}
						/*window.location.href=""*/
					},
					error:function(data){
						alert('失败')
					}
			})
		});
		$('#btn').click(function(){
			var msg = $('#msg').val();
			var msg0 = $('#msg0').val();
			var msg1 = $('#msg1').val();
			var msg2 = $('#msg2').val();
			var msg3 = $('#msg3').val();
			var txt1 = $('#upgrade_state').val();
			var txt2 = $('#earnings_state').val();
			var brandid = sessionStorage.getItem(key=3);
			console.log(txt1)
			console.log(txt2)
			console.log(msg3)
			console.log(brandid)
			console.log(msg)			
					$.ajax({
					type:"POST",
					url:window.baseUrl+"user/thirdlevel/prod/add",
					async:true,
					dataType:"json",
					data:{
						brand_id:brandid,
						grade:msg2,
						name:msg1,
						numOfPeople:msg3,
						discount:1,
						remark:"",
						true_false_buy:msg,
						upgrade_state:txt1,
						earnings_state:txt2						
					},
					success:function(data){
						console.log(data)
						if(data.resp_code == 000000)
						alert("设置成功！");						
					},
					error:function(data){
						alert('失败');
					}
				});		
		})
	});
</script>
	<script>
        var app = angular.module('myApp', []);
        app.controller('customersCtrl', function($scope, $http ){
            var bank = sessionStorage.getItem(key=15);/*获取到产品id*/
            var id = sessionStorage.getItem(key=3);/*获取到产品id*/
            /*$('#f1').val(userid);*/
            var data = {thirdLevelId:bank,brand_id:id}
            console.log(data);
			/*查询各通道三级分销*/
            $http({
                method: 'POST',
                params: data,
                url: window.baseUrl+'user/thirdlevel/rate/query/thirdlevelid'
            }).then(function successCallback(data){
                console.log("请求数据成功...");
                console.log(data.data.result);
                $scope.items2 = data.data.result
            }, function errorCallback(data) {
                console.log("请求数据失败...");
                console.log(data)
            });
            $scope.fd = function(item){
                console.log(item.rate)
                var rate = item.rate;
                var tag = item.channelTag;
            };
            $scope.add = function(item){
				/*修改代理商刷卡费率*/
                console.log(item);
                var bank = sessionStorage.getItem(key=15);/*获取到产品id*/
                var id = item.id;
                var rate = item.rate;
                /*console.log(userid);*/
                console.log(id);
                console.log(rate);
                $http({
                    method:'POST',
                    params:{
                        thirdLevelId:bank,
                        channelId:id,
                        rate:rate
					},
                    url: window.baseUrl+'user/thirdlevel/prod/rate/add'
                }).then(function successCallback(data){
                    console.log("修改数据成功...");
                    console.log(data.data);
                    if(data.data.resp_code == 000000)
                    alert("成功设置【"+item.name+item.channelParams+"】通道刷卡费率为"+item.rate);
                	if(data.data.resp_code == 999999)
                	alert(data.data.resp_message);


                }, function errorCallback(data) {
                    console.log("修改数据失败...");
                    console.log(data)
                })
            }
        });
	</script>
</html>

